import * as types from './mutationType'

const actions = {
    addToCart({commit, state}, res) {
        let p = new Promise(function(success, fail){
            var record = state.home.list.list.find(item => item.goodsId === res.id);
            if (record.inventory > 0) {
                record.inventory--;
                commit(types.ADD_TO_CART, res);
                success("success");
            } else {
                fail("fail", record);
            }
        });
        return p;
    },

    removeToCart({commit}, {id}) {
       commit(types.REMOVE_TO_CART, id);
    },

    clearCart({commit}) {
        
    }
};
export default actions;